|
|
|
|
|
|
|
5. Set up the Resize event procedure of the UserControl to make the text box fit the space that is drawn by the developer when using your control. This Resize event procedure is shown in Listing 14.1. |
|
|
|
|
|
|
|
|
Listing 14.1 LIMITED.ZIPUsing the Resize Event to Make Sure the Control Fills the Space |
|
|
|
|
|
|
|
|
Private Sub UserControl_Resize()
txtCharSet.Height = UserControl.ScaleHeight
txtCharSet.Width = UserControl.ScaleWidth
End Sub |
|
|
|
|
|
|
|
|
The simple two-line Resize event procedure is all the code necessary for the user interface of the sample control. Its purpose is to keep the text box the same size as the UserControl object. |
|
|
|
|
|
|
|
|
Before moving on, test the Resize event procedure by performing the following steps: |
|
|
|
|
|
|
|
|
1. Close the UserControl window. If you have the Toolbox open, notice that a new icon appears for your control. |
|
|
|
|
|
|
|
|
2. Choose File, Add Project. Then add a Standard EXE project. |
|
|
|
|
|
|
|
|
3. Draw your control on Form1, and try resizing it. |
|
|
|
|
|
|
|
|
The purpose of jumping the gun by using the control so quickly is to get you used to the idea that the code in your ActiveX control does not have to be executed explicitly. Remember, when you are developing an ActiveX control, the code you write is used at design time in the host program. |
|
|
|
|
|
|
|
|
For now, remove the Standard EXE project by right-clicking it in the Project Explorer window and choosing Remove Project1. Now, it is time to work on the enhancements to the control. |
|
|
|
|
|
|
|
|
Enhancing the Base Control |
|
|
|
|
|
|
|
|
The enhancement you are going to make to the TextBox control is to tell it whether it should accept any characters, just letters, or just numbers. You can do so by adding your own property, called CharAccept, which can have one of the following three values: |
|
|
|
|
|
|
|
|
Creating the CharAccept Property |
|
|
|
|
|
|
|
|
To create the CharAccept property, you first need to add a private variable to store the property value internally. To do so, create it in the General Declarations section of the UserControl object, as follows: |
|
|
|
|
|
|
|
|
Private mCharAccept As Integer |
|
|
|
|
|